/**
 * mLibFactory.js
 * Created: 25/09/2013
 * Source link: http://code.google.com/p/code-depository/source/browse/
 *
 * By Suresh Nalluri,
 * License: The MIT License (MIT)
 *          See LICENSE details
 * 
 * Factory object class used by the various sub-libraries to create their objects.
 * Each sub-class or library must provide its own prototype init method, which in
 * essence defines the object sttructure for that library.
 *
 *  eg. mLIB.abc = Factory.obj();
 *      mLIB.abc.prototype.init = function() {
 *          this.x = blah;
 *          this.y = moreblah;
 *      }
 *
 ****************************************************************************
 */

if (typeof Factory == 'undefined') function Factory() {};

Factory.isClass = function(theObj, objClass){
	return theObj && theObj.hasOwnProperty && theObj instanceof objClass;
};

Factory.getClass = function(theObj){
	return theObj && theObj.hasOwnProperty && theObj.getClass &&theObj.getClass();
};

Factory.obj = function(proto) {
    function ClassWrapper() {
		var obj = this;
		if ( !(obj instanceof ClassWrapper) ) {
			var F = function() {}, obj;
			F.prototype = ClassWrapper.prototype;
			obj = new F();
		}
		if (obj.init) obj.init.apply(obj, arguments);
		return obj;
    }
	
	// we'll provide some standard default methods.
    ClassWrapper.prototype.isClass = function(objClass){
		return this instanceof objClass;
    };
    ClassWrapper.prototype.getClass = function(){
		return this.constructor;
    };

    if (proto) {
        for (var f in proto) {
            proto.hasOwnProperty(f) && (ClassWrapper.prototype[f] = proto[f]);
        };
    }
    return ClassWrapper;
};